package com.kemai.designmode.strategy

import com.kemai.common.utils.AppUtils
import com.kemai.designmode.entry.Fruit




/**

 *@description:
 * @author: zhaoshanshan
 * @date: 2022/10/4 8:16 上午

 */
abstract class DiscountShoppingCart(private var products: List<Fruit>,private var discount: Discount) {

    fun submitOrder(){
        var money = calculateBalance()
        AppUtils.getInstance()?.showToast("优惠前金额${money}")
        money = discount.calculate(money)
        AppUtils.getInstance()?.showToast("优惠后金额${money}")
        pay(money)
        sendHome()


    }
    //计算金额
    private fun calculateBalance():Double{
      var money = 0.0
      for (i in products.indices){
          money += products[i].price()

      }
      return money
    }
    //支付金额
    abstract fun  pay(money:Double)
    //送货上门
    private fun sendHome(){
        AppUtils.getInstance()?.showToast("我将送货上门")
    }

}